package db;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
/*import com.theopentutorials.jdbc.db.DbUtil;
import com.theopentutorials.jdbc.db.JDBCMySQLConnection;
import com.theopentutorials.jdbc.to.Employee;*/
 
public class TvsDB {
    
	private static TvsDB demo;
    private static ResultSet rs;
    private static Connection connection;
    private static Statement statement ; 
	
	
	public TvsDB() {
        try {
        	demo = new TvsDB();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
 
    public static ResultSet openDB(String query)  {
        rs = null;
        connection = null;
        statement = null; 
 
        try {
            connection = MySqlConnection.getConnection();
            statement = connection.createStatement();
            rs = statement.executeQuery(query);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
    
    public static String updateDB(String query)
    {
    	rs = null;
        connection = null;
        statement = null; 
 
        try {
            connection = MySqlConnection.getConnection();
            statement = connection.createStatement();
            statement.executeUpdate(query);
            closeDB();
            return "success";
        } catch (SQLException e) {
            e.printStackTrace();
            return "failure";
        }
    }
    public static void closeDB()
    {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

/*import com.mysql.jdbc.Driver;

public class TvsDB {
	ResultSet rs = null;
    Connection connection = null;
    Statement statement = null; 

    Employee employee = null;
    String query = "SELECT * FROM employee WHERE emp_id=" + employeeId;
    try {
        connection = JDBCMySQLConnection.getConnection();
        statement = connection.createStatement();
        rs = statement.executeQuery(query);

        if (rs.next()) {
            employee = new Employee();
            employee.setEmpId(rs.getInt("emp_id"));
            employee.setEmpName(rs.getString("emp_name"));
            employee.setDob(rs.getDate("dob"));
            employee.setSalary(rs.getDouble("salary"));
            employee.setDeptId((rs.getInt("dept_id")));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    return employee;
}
*/